<template>
	<view>
		个人资料中心
		<u-button type="primary" @click="uploadHead">上传头像</u-button>
	</view>
</template>

<script>
	import {createNamespacedHelpers} from 'vuex'
	const {mapState:mapUserState}=createNamespacedHelpers('user')
	export default {
		data() {
			return {
				
			}
		},
		computed:{
			...mapUserState(['authToken','userInfo'])
		},
		methods: {
			async getSafe(){
				const uid=this.userInfo.uid;
				const auth_token=this.authToken;
				const result=await uni.$api.mine.safeApi({uid,auth_token})
				if(!result.data.status){
					uni.navigateTo({
						url:'/pages/login/login'
					})
				}
			},
			async uploadHead(){
				const {tempFiles}=await uni.chooseImage({
					count:1,
					sizeType:['original'],
					sourceType:['album','camera']
				})
				const result=await uni.uploadFile({
					url:'http://vueshop.glbuys.com/api/user/myinfo/formdatahead?token=1ec949a15fb709370f',
					formData:{
						"headfile":tempFiles[0]
					}
				})
				console.log('文件上传的最终结果',JSON.parse(result.data).data.msbox);
			}
		},
		onShow() {
			this.getSafe()
		}
	}
</script>

<style>

</style>
